﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;

namespace ZF.WS.UserControls.Index
{
    public partial class Medium : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //using (var dc = SiteInfo.CreateDBDataContext())
            //{
            //    List<object> zjList = null;

            //    var cacheKey = "_index_Medium";
            //    var obj = HttpCache.GetCache(cacheKey);
            //    if (obj != null)
            //    {
            //        zjList = obj as List<object>;
            //    }
            //    else
            //    {
            //        zjList = dc.US_Member.Where(p => p.Status == 1 && p.IsMedium && p.Type == 1)
            //        .OrderByDescending(p => p.MemberId).Take(5).ToList().Select(p =>
            //        (object)new
            //        {
            //            Member = p
            //        }).ToList();
            //        SiteInfo.Instance.SetCache(cacheKey,zjList, SiteInfo.Instance.SystemConfig.DefCacheTimeSpan);
            //    }



 
            //    this.lvNewZJ.DataSource = zjList;
            //    this.lvNewZJ.DataBind();
            //}
 

            var typeList = DictionaryConfig.EExpertType.Where(p => p.Key == 3 || p.Key == 4).ToList();
            this.lvTitle.DataSource = typeList;
            this.lvTitle.DataBind();
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                Dictionary<object, List<object>> dicType =null;
                var cacheKey = "_Index_Medium";
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null)
                {
                    dicType = obj as Dictionary<object, List<object>>;
                }
                else
                {
                    dicType = new Dictionary<object, List<object>>();
                    foreach (var type in typeList)
                    {
                        var list = dc.US_Member.Where(p => p.IsExpert)
                            .Where(p => p.ExpertType == type.Key)
                            .OrderByDescending(p => p.Hits)
                            .OrderByDescending(p => p.MemberId)
                             .Take(8).ToList().Select(p =>
                             (object)new
                             {
                                 Member = p,
                                 EType = DictionaryConfig.EExpertType.FirstOrDefault(t => t.Key == p.ExpertType).Text
                             }).ToList();
                 

                        list = list.Take(6).ToList();
                        dicType[type.Key] = list;
                    }
                    SiteInfo.Instance.SetPageCache(cacheKey, dicType);
                }
                this.lvList.DataSource = dicType;
                this.lvList.DataBind();

 







            }
        }
    }
}